<template>
  <div class="movie_body" ref="movie_body">
    <Loading v-if="isLoading"/>
    <Scroller v-else :handle-to-scroll="handleToScroll" :handle-to-pulling-down="handleToPullingDown">
      <ul>
        <li class="pull_down">{{ pullDownMsg }}</li>
        <li v-for="item in movieList" :key="item.id" >
          <div class="pic_show" @tap="handleToDetail(item.id)"><img :src="item.img | setHW('128.180')"></div>
          <div class="info_list"  @tap="handleToDetail(item.id)">
            <h2>{{ item.nm }} <img v-if="item.version=='3d imax'" src="@/assets/3DIMAX.png" alt=""></h2>
            <p>观众评 <span class="grade">{{ item.sc }}</span></p>
            <p>主演: {{ item.star }}</p>
            <p>{{ item.showinfo }}</p>
          </div>
          <div class="btn_mall">
            购票
          </div>
        </li>
        <li class="more">{{ more }}</li>
      </ul>
    </Scroller>
  </div>
</template>

<script>
// import BScroll from 'better-scroll';

export default {
  name: "NowPlaying",
  data() {
    return {
      movieList: [],
      pullDownMsg: '',
      more: '',
      isLoading: true,
      prevCityId: -1
    }
  },
  activated() {
    var cityId = this.$store.state.city.id;
    if (this.prevCityId === cityId) {
      return;
    }
    this.isLoading = true;
    this.axios.get('/api/movieOnInfoList?cityid=' + cityId).then((res) => {
      var msg = res.data.msg;
      if (msg === '成功') {
        this.movieList = res.data.data;
        this.isLoading = false;
        this.prevCityId = cityId;
      }
    });
  },
  created() {

  },
  methods: {
    handleToDetail(movieId) {
      this.$router.push('/movie/detail/1/'+movieId);
    },
    handleToPullingDown() {
      var cityId = this.$store.state.city.id;
      this.axios.get('/api/movieOnInfoList?cityid=' + cityId).then((res) => {
        var msg = res.data.msg;
        if (msg === '成功') {
          // this.more = '点击查看更多'
          setTimeout(() => {
            this.movieList = res.data.data;
            this.pullDownMsg = '加载成功';
            setTimeout(() => {
              this.pullDownMsg = '';
            }, 500);
          }, 1000);
        }

      });
    },
    handleToScroll(pos) {
      if (pos.y > 100) {
        this.pullDownMsg = '下拉松手开始加载...';
      }
    },
    handleToPullingUp() {
      /*if (pos.y > 50) {
        this.more = '没有更多数据了';
        return;
      }*/
      this.axios.get('/api/movieOnInfoList?cityid=241').then((res) => {
        var msg = res.data.msg;
        if (msg === '成功') {
          setTimeout(() => {
            this.more = '加载成功'
            this.movieList = res.data.data
            setTimeout(() => {
              this.more = ''
            }, 500)
          }, 3000)
        }
      });
    },
    handleToTouchEnd(pos) {
      if (pos.y > 50) {
        this.axios.get('/api/movieOnInfoList?cityid=241').then((res) => {
          var msg = res.data.msg;
          if (msg === '成功') {
            setTimeout(() => {
              this.movieList = res.data.data
              this.pullDownMsg = '加载成功'
              setTimeout(() => {
                this.pullDownMsg = ''
              }, 500)
            }, 1000)
          }
        });
      }
    }
  }
}
</script>

<style scoped>
#content .movie_body {
  flex: 1;
  overflow: auto;
}

.movie_body ul {
  margin: 0 12px;
  overflow: hidden;
  /*height: 19999px;*/

}

.movie_body ul li {
  margin-top: 12px;
  display: flex;
  align-items: center;
  border-bottom: 1px #e6e6e6 solid;
  padding-bottom: 10px;
}

.movie_body .pic_show {
  width: 64px;
  height: 90px;
}

.movie_body .pic_show img {
  width: 100%;
}

.movie_body .info_list {
  margin-left: 10px;
  flex: 1;
  position: relative;
}

.movie_body .info_list h2 {
  font-size: 17px;
  line-height: 24px;
  width: 150px;
  overflow: hidden;
  white-space: nowrap;
  text-overflow: ellipsis;
}

.movie_body .info_list p {
  font-size: 13px;
  color: #666;
  line-height: 22px;
  width: 200px;
  overflow: hidden;
  white-space: nowrap;
  text-overflow: ellipsis;
}

.movie_body .info_list .grade {
  font-weight: 700;
  color: #faaf00;
  font-size: 15px;
}

.movie_body .info_list img {
  width: 50px;
  position: absolute;
  right: 10px;
  top: 5px;
}

.movie_body .btn_mall, .movie_body .btn_pre {
  width: 47px;
  height: 27px;
  line-height: 28px;
  text-align: center;
  background-color: #f03d37;
  color: #fff;
  border-radius: 4px;
  font-size: 12px;
  cursor: pointer;
}

.movie_body .btn_pre {
  background-color: #3c9fe6;
}

.movie_body .pull_down {
  margin: 0;
  padding: 0;
  border: none;
}

.movie_body .more {
  margin: 0;
  padding: 0;
  border: none;
}
</style>
